package com.foreknow.demo5;

/**
 * throws和throw的区别
 * 1. throws表示异常的声明，表示某个方法中有可能会产生某种异常
 * 2. throw表示人为抛出异常 throw new 异常类的对象()
 */
public class Test {
    public int add(int a,int b) throws NegativeNumberException{
        if(a < 0 || b < 0) {
            throw new NegativeNumberException();
        }
        return a + b;
    }
    public static void main(String[] args) {
        Test test = new Test();
        try {
            test.add(-3,2);
        } catch (NegativeNumberException e) {
            e.printStackTrace();
        }
    }
}
